package com.xzxy.xmlg_backend.controller;

import com.xzxy.xmlg_backend.entity.Result;
import com.xzxy.xmlg_backend.service.WebSocketService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * WebSocket通知测试控制器
 * @author zys
 * @since 2025-06-23
 */
@RestController
@RequestMapping("/api/notification")
@Tag(name = "WebSocket通知测试")
public class NotificationTestController {

    @Autowired
    private WebSocketService webSocketService;

    /**
     * 发送测试通知
     * @return
     */
    @PostMapping("/test")
    @Operation(summary = "发送测试通知", description = "发送WebSocket测试通知消息")
    public Result sendTestNotification() {
        try {
            // 发送简单文本消息
            webSocketService.sendNotification("这是一条测试通知消息！");
            
            return Result.success("测试通知发送成功");
        } catch (Exception e) {
            return Result.fail("发送测试通知失败: " + e.getMessage());
        }
    }

    /**
     * 发送自定义通知
     * @param title 标题
     * @param content 内容
     * @param type 类型
     * @return
     */
    @PostMapping("/custom")
    @Operation(summary = "发送自定义通知", description = "发送自定义WebSocket通知消息")
    public Result sendCustomNotification(
            @RequestParam(defaultValue = "系统通知") String title,
            @RequestParam(defaultValue = "这是一条自定义通知") String content,
            @RequestParam(defaultValue = "info") String type) {
        try {
            webSocketService.sendNotification(title, content, type);
            return Result.success("自定义通知发送成功");
        } catch (Exception e) {
            return Result.fail("发送自定义通知失败: " + e.getMessage());
        }
    }
}